export default {
  namespaced: true,
  state: {
    // 歌手信息
    singer: {},
    //播放状态
    isPlaying: sessionStorage.getItem('isPlaying') ? sessionStorage.getItem('isPlaying') : false,
    //当前歌单id
    songListId: "",
    //播放列表
    playList: [],
    //历史播放列表
    hisMusicList: [],
    //当前播放歌曲url
    musicUrl: sessionStorage.getItem('musicUrl') ? sessionStorage.getItem('musicUrl') : "",
    //当前播放歌曲详情
    musicDeatil: sessionStorage.getItem('musicDetail') ? JSON.parse(sessionStorage.getItem('musicDetail')) : {},
    //当前播放歌曲id
    songId: sessionStorage.getItem('songId') ? sessionStorage.getItem('songId') : "",
    //当前歌曲进度
    nowDuration: 0,
    //当前播放模式
    playOrd: 0,
    //播放过的歌曲id
    hasPlayList: sessionStorage.getItem('hasPlayList') ? JSON.parse(sessionStorage.getItem('hasPlayList')) : [],
    //播放时间
    currentTime: '00:00',
    // 加载状态
    isLoading: false,
    //歌曲时长
    durationTime: sessionStorage.getItem('durationTime') ? sessionStorage.getItem('durationTime') : '',
    //当前播放音量
    volumeVal: sessionStorage.getItem('volumeVal') ? sessionStorage.getItem('volumeVal') * 1 : 50,
    //歌曲时长秒数
    maxTime: sessionStorage.getItem('maxTime') ? sessionStorage.getItem('maxTime') * 1 : 0,

  },
  mutations: {
    // 保存播放状态
    saveIsPlaying(state, isPlaying) {
      state.isPlaying = isPlaying;
    },
    //保存当前歌单id
    saveSongListId(state, songListId) {
      state.songListId = songListId;
    },
    // 添加当前播放列表
    unshiftPlayList(state, playList) {
      state.playList.unshift(playList);
    },
    // 添加历史记录播放列表
    unshiftHisMusicList(state, hisMusicList) {
      state.hisMusicList.unshift(hisMusicList);
    },

    pushPlayList(state, playList) {
      console.log(playList);
      // state.hasPlayList:[...playList]
      [...state.playList, ...playList];
    },
    // 添加历史记录播放列表
    unshiftHisMusicList(state, hisMusicList) {
      state.hisMusicList.unshift(hisMusicList);
    },
    // 保存当前正在播放的音乐路径
    saveMusicUrl(state, musicUrl) {
      state.musicUrl = musicUrl
    },
    // 保存当前正在播放的音乐细节
    saveMusicDetail(state, musicDetail) {
      state.musicDetail = musicDetail
    },
    // 保存当前正在播放的歌曲id
    saveSongId(state, songId) {
      state.songId = songId
    },
    //保存播放歌曲信息
    saveHasPlayList(state, songId) {
      // console.log(state.hasPlayList);
      state.hasPlayList.push(songId)
      sessionStorage.setItem('hasPlayList', JSON.stringify(state.hasPlayList))
    },
    //保存播放时间
    saveCurrentTime(state, currentTime) {
      state.currentTime = currentTime
    },
    // 修改当前加载状态
    changeIsLoading(state, isLoading) {
      state.isLoading = isLoading
    },
    //保存歌曲时长
    saveDurationTime(state, durationTime) {
      state.durationTime = durationTime
    },
    //保存当前播放音量
    saveVolumeVal(state, volumeVal) {
      state.volumeVal = volumeVal
    },
    //保存歌曲时长秒数
    savemaxTime(state, maxTime) {
      state.maxTime = maxTime
    },

  },

  actions: {
    // 保存播放状态
    saveIsPlaying({
      commit
    }, payload) {
      commit('saveIsPlaying', payload);
    },
    //添加到当前播放列表
    unshiftPlayList({
      commit
    }, payload) {
      commit('unshiftPlayList', payload)
    },
    pushPlayList({
      commit
    }, payload) {
      commit('pushPlayList', payload)
    },
    // 添加到历史记录播放列表
    unshiftHisMusicList({
      commit
    }, payload) {
      commit('unshiftHisMusicList', payload)
    },

    // 添加到播放过的歌曲歌单(避免上一首或者随机播放播放到重复的歌曲)
    pushHasPlayList({
      commit
    }, payload) {
      commit('pushHasPlayList', payload)
    },

    // 删除当前列表歌曲
    deletePlayListSong({
      commit
    }, payload) {
      commit('deletePlayListSong', payload)
    },

    // 删除历史列表歌曲
    deleteHisListSong({
      commit
    }, payload) {
      commit('deleteHisListSong', payload)
    },

    // 删除已经播放列表歌曲
    deleteHasListSong({
      commit
    }, payload) {
      commit('deleteHasListSong', payload)
    },

    // 清空歌单
    deleteAllList({
      commit
    }) {
      commit('deleteAllList')
    },
    // 播放所有歌曲
    playAllSong({
      commit
    }, payload) {
      commit('playAllSong', payload)
    },
    // 保存当前播放模式
    savePlayOrd({
      commit
    }, payload) {
      commit('savePlayOrd', payload)
    },
    // 保存当前正在播放的音乐路径
    saveMusicUrl({
      commit
    }, payload) {
      commit('saveMusicUrl', payload)
    },
    // 保存当前正在播放的音乐细节
    saveMusicDetail({
      commit
    }, payload) {
      commit('saveMusicDetail', payload)
    },
    // 保存当前正在播放的歌曲id
    saveSongId({
      commit
    }, payload) {
      commit('saveSongId', payload)
    },
    // 让播放过的歌曲等于当前歌单
    sameHasAndPlay({
      commit
    }) {
      commit('sameHasAndPlay')
    },
    // 保存当前搜索信息
    saveSearchInfo({
      commit
    }, payload) {
      commit('saveSearchInfo', payload)
    },
    // 改变当前加载状态
    changeIsLoading({
      commit
    }, payload) {
      commit('changeIsLoading', payload)
    },
    // 保存开始和结束时间
    saveAur({
      commit
    }, payload) {
      commit('saveAur', payload)
    },
    // 保存进度条当前进度
    saveNowDuration({
      commit
    }, payload) {
      commit('saveNowDuration', payload)
    },
    //保存播放过歌曲的id
    saveHasPlayList({
      commit
    }, payload) {
      commit('saveHasPlayList', payload)
    },
    //保存歌单id
    saveSongListId({
      commit
    }, payload) {
      commit('saveSongListId', payload)
    },
    //保存歌曲时长
    saveDurationTime({
      commit
    }, payload) {
      commit('saveDurationTime', payload)
    },
    //保存当前播放音量
    saveVolumeVal({
      commit
    }, payload) {
      commit('saveVolumeVal', payload)
    },
    //保存歌曲时长秒数
    savemaxTime({
      commit
    }, payload) {
      commit('savemaxTime', payload)
    },
  },
  getters: {
    // 播放状态
    isPlaying: state => state.isPlaying,

    // 当前播放列表
    playList: state => state.playList,

    //当前歌单id
    songListId: state => state.songListId,

    // 历史播放列表
    hisMusicList: state => state.hisMusicList,

    // 播放过的歌曲歌单(避免上一首或者随机播放播放到重复的歌曲)
    hasPlayList: state => state.hasPlayList,

    // 当前播放模式
    playOrd: state => state.playOrd,

    // 当前播放歌曲url
    musicUrl: state => state.musicUrl,

    // 当前播放歌曲细节
    musicDetail: state => state.musicDetail,

    // 当前播放歌曲id
    songId: state => state.songId,

    // 当前进度条
    nowDuration: state => state.nowDuration,

    // 当前搜索信息
    searchInfo: state => state.searchInfo,

    // 当前加载状态
    isLoading: state => state.isLoading,

    // 开始和结束时间段
    slider: state => state.slider,
    playDur: state => state.playDur,

    // 搜索历史
    searchHistory: state => state.searchHistory,
    //歌曲时长
    durationTime: state => state.durationTime,
    //当前播放音量
    volumeVal: state => state.volumeVal,
    //歌曲时长秒数
    maxTime: state => state.maxTime,
    //歌曲当前时长
    currentTime: state => state.currentTime
  }
}
